package com.example.reactor.rsocket.controller;

import com.example.reactor.rsocket.config.MessageClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/**
 * @author zpMeng
 * @since 10/12/2024
 */
@Configuration
@Slf4j
public class InvokeClientConfig {

    //@Bean
    public ApplicationRunner normalRequestAndNormalResponse(MessageClient client) {
        return args ->
                System.out.println(client.normalRequestAndNormalResponse("to normalRequestAndNormalResponse"));
    }

    //@Bean
    public ApplicationRunner requestAndResponseStream(MessageClient client) {
        return args -> client.requestAndResponseStream("meepwn")
                .doOnNext(message -> {
                    System.out.println("Response is :" + message);
                })
                .subscribe();
    }

    //@Bean
    public ApplicationRunner fireAndForget(MessageClient client) {
        return args -> client
                .fireAndForget(Mono.just("fireAndForget request param"))
                .subscribe();
    }

    //@Bean
    public ApplicationRunner streamRequestAndStreamResponse(MessageClient client) {
        return args -> client.monoRequestAndMonoResponse(Mono.just("Stream Request, Stream Response"))
                .doOnNext(System.out::println)
                .subscribe();
    }

    //@Bean
    public ApplicationRunner streamRequestAndStreamResponse2(MessageClient client) {
        return args -> client.fluxRequestAndFluxResponse(Flux.range(1, 10)
                        .map(i -> "request -- " + i))
                .doOnNext(System.out::println)
                .subscribe();
    }

    //@Bean
    public ApplicationRunner multiParam(MessageClient client) {
        return args -> client.multiParam("fm", Mono.just("multiParam request"))
                .doOnNext(System.out::println)
                .subscribe();
    }

}